package com.sky.cloudbabaapplication.service.impl;

import com.sky.cloudbabaapplication.annotation.IResource;
import com.sky.cloudbabaapplication.service.IOrderStockService;
import com.sky.cloudbabaserviceapi.service.IStocksService;
import com.supsky.serviceapi2.dto.OrderDto;
import com.supsky.serviceapi2.service.IOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class OrderStockService implements IOrderStockService {

    @IResource
    private IOrderService orderService;

    @IResource
    private IStocksService stocksService;


    @Override
    @GlobalTransactional
    public void buy(Long goodId) {
        OrderDto orderDto = new OrderDto();

        orderDto.setUserId(1L);
        orderDto.setStatus((byte)1);
        orderDto.setCreateDate(new Date());
        orderService.saveOrder(orderDto);
        stocksService.reduceStock(goodId,1);
    }
}
